package cn.xxd.xxdssoservice.service;

import cn.xxd.entity.ReturnT;
import cn.xxd.entity.ShopUser;
import cn.xxd.entity.XxdAddress;
import cn.xxd.xxdssointerface.UserService;
import cn.xxd.xxdssoservice.dao.LoginUserDao;
import cn.xxd.xxdssoservice.dao.ShopUserDao;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(version = "1.0.0", interfaceClass = UserService.class)
public class UserServiceImpl implements UserService {

    @Autowired
    private ShopUserDao shopUserDao;

    @Autowired
    private LoginUserDao loginUserDao;

    @Override
    @Transactional
    public ReturnT addAddress(XxdAddress address) {
        address.setDel("0");
        try {
            shopUserDao.addAddress(address);
        } catch (Exception e) {
            e.printStackTrace();
            return new ReturnT(500, "failed");
        }
        return new ReturnT(200, "success");
    }

    @Override
    public List<XxdAddress> getAddressList(String id) {
        List<XxdAddress> list = shopUserDao.getAddressList(id);
        return list;
    }

    @Override
    public int changeStatus(String id) {
        return shopUserDao.changeStatus(id);
    }

    @Override
    public int changeOpt(String id) {
        return shopUserDao.changeOpt(id);
    }

    @Override
    public int delAddress(String id) {
        return shopUserDao.delAddress(id);
    }

    @Override
    public ShopUser getShopUserByUserId(String id) {
        return shopUserDao.getShopUserByUserId(id);
    }

    @Override
    public int editLoginUser(String id, String name) {
        return loginUserDao.editLoginUser(id, name);
    }
}
